<?php
/**
 * Created by PhpStorm.
 * User: Kau
 * Date: 2017/12/30
 * Time: 17:14
 */
namespace app\controllers;

use app\models\User;
use Yii;
use yii\web\Controller;

class MemberController extends Controller {

    /**
     * 用户登录
     * @return string|\yii\web\Response
     */
    public function actionAuth() {
        $this->layout = 'layout2';
        $model = new User();
        if (Yii::$app->request->isPost) {
            $post = Yii::$app->request->post();
            if ($model->login($post)) {
                return $this->goBack(Yii::$app->request->referrer);
            }
        }

        return $this->render("auth", ['model' => $model]);
    }

    /**
     * 用户登出
     * @return \yii\web\Response
     */
    public function actionLogout() {
        Yii::$app->session->remove('loginname');
        Yii::$app->session->remove('isLogin');
        if (!isset(Yii::$app->session['isLogin'])) {
            return $this->goBack(Yii::$app->request->referrer);
        }
    }

    /**
     * 用户注册
     * @return string
     */
    public function actionReg() {
        $model = new User();
        if (Yii::$app->request->isPost) {
            $post = Yii::$app->request->post();
            if ($model->regByMail($post)) {
                Yii::$app->session->setFlash('info', '电子邮件发送成功');
            }
        }
        $this->layout = 'layout2';
        $model->userpass = '';
        return $this->render('auth', ['model' => $model]);
    }



}